package labs.fourth;

import static labs.utilities.PrintUtilities.printError;
import static labs.utilities.PrintUtilities.printException;
import static labs.utilities.PrintUtilities.printInfo;
import labs.utilities.LabsFileReader;

public class SyntacticAnalyzer extends ErrorReport{
	private String inputFileName;
	private LabsFileReader reader;
//	private Yylex yy;

	public SyntacticAnalyzer(String fileName) {
		this.inputFileName = fileName;
	}

	public boolean start() {
		try {
			printInfo("Start Parsing File: '%s'", inputFileName);
			reader = new LabsFileReader(inputFileName);
			String[] lines = reader.readLines(true);
			printInfo("%s lines are read", lines.length);
			lines = null;
			if (reader.isOpened()) {
				reader.reset();
				printInfo("Start parsing process. . .");
				Lexer.start(reader.getStreamReader());
				if (SyntaxParser.start(Lexer.tokens)) {
					return true;
				}
				// new SyntaxParser().start(yy);
				reader.close();
			}
			printInfo("End Parsing File: '%s'", inputFileName);
		} catch (Exception e) {
			printError("Some error at lab-4");
			printException(e);
		}
//		setErrorMessage(SyntaxParser.getTokensList().peek());
		return false;
	}
}
